from common.Ultils import BlogDriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class BlogDelete:
    url=""
    driver=""

    # 构造函数
    def __init__(self):
        self.url="http://8.137.19.140:9090/blog_detail.html?blogId=44793"
        self.driver = BlogDriver.driver
        self.driver.get(self.url)
    def BlogDeleteTest(self):
        #找到删除按钮
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.right > div > div.operating > button:nth-child(2)").click()
        #显示等待直到弹窗的出现
        WebDriverWait(self.driver,5).until(EC.alert_is_present())
        alert = self.driver.switch_to.alert
        alert_text = alert.text
        alert.accept()

    def BlogDeleteByNoLogin(self):
        username = self.driver.find_element(By.CSS_SELECTOR, "#username").text
        password = self.driver.find_element(By.CSS_SELECTOR, "#password").text
        assert username == "" and password == ""